package com.topscore.uke.mvp.presenters;

import com.topscore.uke.entities.AchievementInfo;
import com.topscore.uke.mvp.contractors.GetAchievementContractor;
import com.topscore.uke.mvp.model.GetAchievementModel;
import com.topscore.uke.network.BaseResponse;
import com.topscore.uke.utils.UserInfoManager;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by 71468 on 2018/3/27.
 */

public class GetAchievementPresenter implements GetAchievementContractor,GetAchievementContractor.Presenter {

    private View mView;
    private Model mModel;

    private Map<String,Object> mRequest;

    public GetAchievementPresenter(View view) {
        this.mView = view;

        this.mModel = new GetAchievementModel(new CallBack() {
            @Override
            public void onGetDataSuccess(BaseResponse<AchievementInfo> response) {
                mView.onGetPerformanceDataSuccess(response.getData());
            }

            @Override
            public void onError(int errorCode, String errorMessage) {
                mView.onFail(errorCode,errorMessage);
            }

            @Override
            public void onComplete() {
                mView.onLoadFinished();
            }
        });
    }

    @Override
    public void getPerformance() {
        mView.onLoading("");
        mRequest = new HashMap<>();
        mRequest.put("role", UserInfoManager.getUserInfo().getRole());
        mRequest.put("loginName",UserInfoManager.getUserInfo().getLoginName());
        mModel.getAchievement(mRequest);
    }

    @Override
    public void getPerformance(String startTime, String endTime) {
        mView.onLoading("");
        mRequest = new HashMap<>();
        mRequest.put("role", UserInfoManager.getUserInfo().getRole());
        mRequest.put("loginName",UserInfoManager.getUserInfo().getLoginName());
        mRequest.put("startTime",startTime);
        mRequest.put("endTime",endTime);
        mModel.getAchievement(mRequest);
    }
}
